//
//  XTStatusCellCell.swift
//  HrenryWeibo
//
//  Created by 熊涛 on 16/5/17.
//  Copyright © 2016年 熊涛. All rights reserved.
//

import UIKit

class XTStatusCellCell: UITableViewCell {

    //MARK: - 属性
    var status : XTStatus?{
        didSet {
            //原创
            originalView.status = status
            
            
            //转发
            retweetView.retweetStatus = status?.retweeted_status
            
        }
        
    }
    

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    //注册cell后,系统创建cell的时候回调用这个构造函数
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        //准备子控件
        prepareUI()
    }

    
    //准备子控件
    private func prepareUI() {
    
        //背景颜色
        self.backgroundColor = UIColor(white: 237/255.0, alpha: 1)
        //添加子控件
        contentView.addSubview(originalView)
        contentView.addSubview(retweetView)
        contentView.addSubview(bottomView)
        
        //设置约束
        
        //original
        originalView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentView).offset(10)
            make.leading.equalTo(contentView)
            make.trailing.equalTo(contentView)
            
//            let height = Int(arc4random_uniform(100) + 50)
            //高度要根据内容来决定
//            make.height.equalTo(200)
        }

        
        
        //retweetView
        retweetView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(originalView.snp_bottom)
            make.leading.equalTo(originalView)
            make.trailing.equalTo(originalView)
            //测试
//            make.height.equalTo(200)
        }
        
        
        //bottomView
        bottomView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self)
            make.trailing.equalTo(self)
            make.top.equalTo(retweetView.snp_bottom)
            make.height.equalTo(37)
        }
        
        
        //cell.contentView
        contentView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self)
            make.leading.equalTo(self)
            make.trailing.equalTo(self)
            //contentView的底部参照子控件,不要参照cell,cell的高度本来就是参照contentView
            make.bottom.equalTo(bottomView)
            
        }
        
    }
    
    
    //MARK: - 懒加载
    //原创view
    private lazy var originalView : XTStatusOriginalView = XTStatusOriginalView()
    
    //底部bottonView
    private lazy var bottomView : XTStatusBottomView = XTStatusBottomView()
    
    
    //转发view
    private lazy var retweetView : XTStatusRetweetView = XTStatusRetweetView()

}
